home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / pine / osdep / pw_stuff.fun < prev    next >
Text File  |  1994-06-17  |  2KB  |  85 lines

  1. /*----------------------------------------------------------------------
  2.       Pull the name out of the gcos field if we have that sort of /etc/passwd
  3.  
  4.    Args: gcos_field --  The long name or GCOS field to be parsed
  5.          logname    --  Replaces occurances of & with logname string
  6.  
  7.  Result: returns pointer to buffer with name
  8.   ----*/
  9. static char *
  10. gcos_name(gcos_field, logname)
  11.     char *logname, *gcos_field;
  12. {
  13.     char *firstcp, *lastcp;
  14.  
  15.     /* The last character of the full name is the one preceding the first
  16.      * '('. If there is no '(', then the full name ends at the end of the
  17.      * gcos field.
  18.      */
  19.     if(lastcp = strindex(gcos_field, '('))
  20.     *lastcp = '\0';
  21.  
  22.     /* The first character of the full name is the one following the 
  23.      * last '-' before that ending character. NOTE: that's why we
  24.      * establish the ending character first!
  25.      * If there is no '-' before the ending character, then the fullname
  26.      * begins at the beginning of the gcos field.
  27.      */
  28.     if(firstcp = strrindex(gcos_field, '-'))
  29.     firstcp++;
  30.     else
  31.     firstcp = gcos_field;
  32.  
  33.     return(firstcp);
  34. }
  35.  
  36.  
  37. /*----------------------------------------------------------------------
  38.       Fill in homedir, login, and fullname for the logged in user.
  39.       These are all pointers to static storage so need to be copied
  40.       in the caller.
  41.  
  42.  Args: ui    -- struct pointer to pass back answers
  43.  
  44.  Result: fills in the fields
  45.   ----*/
  46. void
  47. get_user_info(ui)
  48.     struct user_info *ui;
  49. {
  50.     struct passwd *unix_pwd;
  51.  
  52.     unix_pwd = getpwuid(getuid());
  53.     if(unix_pwd == NULL) {
  54.       ui->homedir = cpystr("");
  55.       ui->login = cpystr("");
  56.       ui->fullname = cpystr("");
  57.     }else {
  58.       ui->homedir = cpystr(unix_pwd->pw_dir);
  59.       ui->login = cpystr(unix_pwd->pw_name);
  60.       ui->fullname = cpystr(gcos_name(unix_pwd->pw_gecos, unix_pwd->pw_name));
  61.     }
  62. }
  63.  
  64.  
  65. /*----------------------------------------------------------------------
  66.       Look up a userid on the local system and return rfc822 address
  67.  
  68.  Args: name  -- possible login name on local system
  69.  
  70.  Result: returns NULL or pointer to alloc'd string
  71.   ----*/
  72. char *
  73. local_name_lookup(name)
  74.     char *name;
  75. {
  76.     struct passwd *pw = getpwnam(name);
  77.  
  78.     if(pw == NULL)
  79.       return((char *)NULL);
  80.  
  81.     return(cpystr(gcos_name(pw->pw_gecos, name)));
  82. }
  83.  
  84.  
  85.